package suzf.top.usercenter.presenter

import android.util.Log
import suzf.top.base.ext.execute
import suzf.top.base.presenter.BasePresenter
import suzf.top.base.rx.BaseSubscriber
import suzf.top.base.utils.NetWorkUtils
import suzf.top.usercenter.data.protocol.UserInfo
import suzf.top.usercenter.presenter.view.ForgetPwdView
import suzf.top.usercenter.presenter.view.RegisterView
import suzf.top.usercenter.presenter.view.UserInfoView
import suzf.top.usercenter.service.UploadService
import suzf.top.usercenter.service.UserService
import javax.inject.Inject

/**
 *
 *========================
 * Created with AndroidStudio
 * Author:Mr.Su
 * Date:2019-09-07
 * Time:20:56
 * ========================
 */
class UserInfoPresenter @Inject constructor() : BasePresenter<UserInfoView>() {

    @Inject
    lateinit var userService: UserService

    @Inject
    lateinit var uploadService: UploadService

    /**
     * 获取上传凭证
     */
    fun getUploadToken() {
        if (!checkNetWork())
            return
        mView.showLoading()
        uploadService.getUploadToken().execute(object : BaseSubscriber<String>(mView) {
            override fun onNext(t: String) {
                super.onNext(t)
                mView.onGetUploadTokenResult(t)
            }
        }, lifecycleProvider)
    }

    /**
     * 修改用户资料
     */
    fun editUser(userIcon: String, userName: String, userGender: String, userSign: String) {
        if (!checkNetWork())
            return
        mView.showLoading()
        userService.editUser(userIcon,userName,userGender,userSign).execute(object : BaseSubscriber<UserInfo>(mView) {
            override fun onNext(t: UserInfo) {
                super.onNext(t)
                mView.onEditUserResult(t)
            }
        }, lifecycleProvider)
    }
}